package com.ysyc.driver_ee.base;

import android.app.Activity;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.ysyc.driver_ee.tools.LogUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>描述：(这里用一句话描述这个类的作用)</p>
 * 作者： Chan<br>
 * 日期： 2018/10/10 17:15<br>
 * 版本： v1.0<br>
 */
public abstract class BaseAdapter<T> extends RecyclerView.Adapter<BaseAdapter<T>.MyViewHolder> {

    public Activity mActivity;

    public List<T> mList = new ArrayList<>();

    public @LayoutRes int mLayoutView;

    public int captainType;
    public int layoutType;

    public BaseAdapter(Activity activity, @LayoutRes int layoutView) {
        this.mActivity = activity;
        this.mLayoutView = layoutView;
    }

    public BaseAdapter(Activity activity, @LayoutRes int layoutView,int captainType){
        this.mActivity = activity;
        this.mLayoutView = layoutView;
        this.captainType = captainType;
    }


    public BaseAdapter(Activity activity, @LayoutRes int layoutView,int layoutType,int captainType){
        this.mActivity = activity;
        this.mLayoutView = layoutView;
        this.captainType = captainType;
        this.layoutType = layoutType;
    }



    public void bindingList(List<T> mData){
        if (null!=mData) {
            this.mList.clear();
            this.mList.addAll(mData);
            notifyDataSetChanged();
        }
    }

    public void addDataList(List<T> mData){
        if (null!=mData && mData.size()>0) {
            this.mList.addAll(mData);
            notifyDataSetChanged();
        }
    }



    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        MyViewHolder viewHolder = new MyViewHolder(LayoutInflater.from(mActivity).inflate(mLayoutView, viewGroup, false));
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) {
        T t = mList.get(i);
        getItemPosition(i);
        convert(myViewHolder,t);

    }

    public void getItemPosition(int i) {

    }

    /**
     * 利用抽象方法回传出去，每个不一样的Adapter去设置
     *
     * @param item 当前的数据
     */
    public abstract void convert(MyViewHolder holder, T item);


    @Override
    public int getItemCount() {
        return mList.size();
    }


    public class MyViewHolder extends RecyclerView.ViewHolder {

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }
}
